package com.l024.android_ljl.view.main.fragment;

import android.view.View;

import com.l024.android_ljl.R;
import com.l024.android_ljl.cache.CacheManager;
import com.l024.android_ljl.databinding.FragmentMyBinding;
import com.l024.android_ljl.entity.SysUserEntity;
import com.l024.android_ljl.view.login.LoginActivity;
import com.l024.android_ljl.view.main.activity.CollectionActivity;
import com.l024.android_ljl.view.main.activity.CommentActivity;
import com.l024.android_ljl.viewmodel.main.MainViewModel;
import com.quantstack.llcommonlibrary.base.BaseNullFragment;
import com.quantstack.llcommonlibrary.event.OnClickEvent;
import com.quantstack.llcommonlibrary.utils.ActivityUtil;
import com.quantstack.llcommonlibrary.utils.GlideUtil;

/**
 * @author wu_ming_zhi_bei
 * @date 2021/5/7 12:35
 * @Notes 我的页面
 */
public class MyFragment extends BaseNullFragment<MainViewModel, FragmentMyBinding> {

    @Override
    public int getLayoutId() {
        return R.layout.fragment_my;
    }

    @Override
    public void afterCreate() {
        SysUserEntity cacheUser = CacheManager.getInstance().getCacheUser();
        if(cacheUser!=null){
            GlideUtil.loadImage(getActivity(),cacheUser.getAvator(),mViewDataBind.ivAvator);
            mViewDataBind.tvName.setText(cacheUser.getName());
            mViewDataBind.tvPhone.setText(cacheUser.getPhone());
            mViewDataBind.llCollection.setOnClickListener(new OnClickEvent() {
                @Override
                public void singleClick(View v) {
                    go(CollectionActivity.class);
                }
            });
            mViewDataBind.llComment.setOnClickListener(new OnClickEvent() {
                @Override
                public void singleClick(View v) {
                    go(CommentActivity.class);
                }
            });

            mViewDataBind.llExit.setOnClickListener(new OnClickEvent() {
                @Override
                public void singleClick(View v) {
                    //移除所有activity
                    ActivityUtil.getInstance().finishAllActivity();
                    //清除缓存
                    CacheManager.getInstance().clearUserInfo();
                    go(LoginActivity.class);
                }
            });
        }
    }
}